﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

using Check_out;
using HotelManagement.DAO;

namespace HotelManagement.DAO
{
    class CheckoutDAO
    {
        public CheckoutDAO()
        {
        }

        public void search(string roomCode, Check_out.Check_out form)
        {
            DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_MAPHONGTableAdapter roomCodeA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_MAPHONGTableAdapter();

            if (roomCodeA.GetData(roomCode).Count == 0)
            {
                MessageBox.Show("Wrong room code, please try again.");
                return;
            }

            DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_MAKHTableAdapter customerCodeA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_MAKHTableAdapter();

            int customerCode = customerCodeA.GetData(roomCode)[0].MaKH;
            form.setCustomerCode(customerCode.ToString());

            DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_TENKHACHHANGTableAdapter customerNameA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_TENKHACHHANGTableAdapter();

            form.setCustomerName(customerNameA.GetData(customerCode)[0].HoTen);

            form.setRoomCode(roomCode);

            DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_DONGIATableAdapter roomPriceA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_DONGIATableAdapter();

            form.setRoomPrice(int.Parse(roomPriceA.GetData(roomCode)[0].DonGia));

            DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_NGAY_NHAN_PHONGTableAdapter inDateA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_NGAY_NHAN_PHONGTableAdapter();

            form.setInDate(inDateA.GetData(roomCode)[0].NgayDen);

            DA_QLKSDataSetTableAdapters.TRAPHONG_LAY_THONGTIN_DICHVUTableAdapter serviceA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_LAY_THONGTIN_DICHVUTableAdapter();

            form.computeTotalRoomFee();

            form.setService(serviceA.GetData(roomCode));

            form.Invalidate();
        }

        public string getNote(string roomCode, string customerCode, string serviceCode)
        {
            DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_GHICHUTableAdapter noteA =
                new DA_QLKSDataSetTableAdapters.TRAPHONG_TIM_GHICHUTableAdapter();

            return noteA.GetData(roomCode, int.Parse(customerCode), serviceCode)[0].GhiChu;
        }

        public void checkOut(string roomCode)
        {
            RoomBookingManagementDAO rbDAO = new RoomBookingManagementDAO();
            rbDAO.erase(roomCode);
        }
    }
}
